

package controles;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

import modeles.Fournisseur;
import modeles.Stock;

import fenetres.*;

public class ChoiseStockAction implements ActionListener{
	ChoiseStockFrame choiseStockFrame;
	Stock oStock;
	
	public ChoiseStockAction(ChoiseStockFrame _choiseStockFrame){
		choiseStockFrame = _choiseStockFrame;
	}
	@Override 
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		
		if(arg0.getSource() == choiseStockFrame.annulerBut){
			choiseStockFrame.dispose();
		}
		
		if(arg0.getSource() == choiseStockFrame.validerBut){
			int irowSelected = choiseStockFrame.stockTable.getSelectedRow () ;
			if (irowSelected == -1)
			{
				JOptionPane.showMessageDialog (null, "Veuillez selectionner le stock Ã  afficher !", "Gestion Stock", JOptionPane.WARNING_MESSAGE) ;
			}
			else
			{
				oStock = choiseStockFrame.listeInfoStock.get(irowSelected);

				ListProduitStockFrame listeProdStockFrame = new ListProduitStockFrame(choiseStockFrame.userConnected,oStock);
				listeProdStockFrame.setVisible(true); 
				choiseStockFrame.accueil.desktop.add(listeProdStockFrame);
		        try {
		        	listeProdStockFrame.setSelected(true);
		        } catch (java.beans.PropertyVetoException e) {}
		        
		        choiseStockFrame.dispose();
			}
		
		}
	}

}

